
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>条件v-if的首次渲染和重新渲染 · petite-vue源码剖析</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="^_^肥仔John">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="3_initial_rendering_and_rerendering_for_v-for.html" />
    
    
    <link rel="prev" href="1_start_from_static_view.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">前言</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    《Petite-Vue源码剖析》简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../0_intro/1_reason_for_source_reading.html">
            
                <a href="../0_intro/1_reason_for_source_reading.html">
            
                    
                    为什么要读源码
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">在线渲染</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="0_intro.html">
            
                <a href="0_intro.html">
            
                    
                    章节介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="1_start_from_static_view.html">
            
                <a href="1_start_from_static_view.html">
            
                    
                    从静态视图首次渲染开始
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.3" data-path="2_initial_rendering_and_rerendering_for_v-if.html">
            
                <a href="2_initial_rendering_and_rerendering_for_v-if.html">
            
                    
                    条件v-if的首次渲染和重新渲染
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="3_initial_rendering_and_rerendering_for_v-for.html">
            
                <a href="3_initial_rendering_and_rerendering_for_v-for.html">
            
                    
                    循环v-for的首次渲染和重新渲染
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="4_directives/1_attribute_binding.html">
            
                <a href="4_directives/1_attribute_binding.html">
            
                    
                    属性绑定v-bind的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="4_directives/2_event_binding.html">
            
                <a href="4_directives/2_event_binding.html">
            
                    
                    事件绑定v-on的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="4_directives/3_bidirectional_binding.html">
            
                <a href="4_directives/3_bidirectional_binding.html">
            
                    
                    双向绑定v-model的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="4_directives/4_ref.html">
            
                <a href="4_directives/4_ref.html">
            
                    
                    特殊指令ref的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="5_tips_for_template.html">
            
                <a href="5_tips_for_template.html">
            
                    
                    优化手段template的原理和使用技巧
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">响应式系统</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../2_reactivity_system/0_intro.html">
            
                <a href="../2_reactivity_system/0_intro.html">
            
                    
                    章节介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../2_reactivity_system/1_reactive_object_array.html">
            
                <a href="../2_reactivity_system/1_reactive_object_array.html">
            
                    
                    逐行解读reactive如何构建对象和数组的响应式对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../2_reactivity_system/2_reactive_map_set.html">
            
                <a href="../2_reactivity_system/2_reactive_map_set.html">
            
                    
                    逐行解读reactive如何构建Map和Set的响应式对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../2_reactivity_system/3_register_side_effect.html">
            
                <a href="../2_reactivity_system/3_register_side_effect.html">
            
                    
                    逐行解读effect如何注册副作用函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../2_reactivity_system/4_cleanup_algorithm.html">
            
                <a href="../2_reactivity_system/4_cleanup_algorithm.html">
            
                    
                    依赖清理优化算法详解-算法思路
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../2_reactivity_system/5_smi.html">
            
                <a href="../2_reactivity_system/5_smi.html">
            
                    
                    依赖清理优化算法详解-基于JavaScript引擎的SMI进一步压榨性能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../2_reactivity_system/6_trigger_and_scheduler.html">
            
                <a href="../2_reactivity_system/6_trigger_and_scheduler.html">
            
                    
                    逐行解读trigger和调度器
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">沙箱模型</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../3_sandbox.html">
            
                <a href="../3_sandbox.html">
            
                    
                    模板表达式的沙箱模型
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >条件v-if的首次渲染和重新渲染</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x6761;&#x4EF6;v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x548C;&#x66F4;&#x65B0;&#x6E32;&#x67D3;"><b>1. </b>&#x6761;&#x4EF6;v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x548C;&#x66F4;&#x65B0;&#x6E32;&#x67D3;</a></li><ul><li><span class="title-icon "></span><a href="#v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;"><b>1.1. </b>v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;</a></li><ul><li><span class="title-icon "></span><a href="#&#x89E3;&#x6790;span-v-ifstatus--offline-offline-span"><b>1.1.1. </b>&#x89E3;&#x6790;<span v-if="status === &apos;offline&apos;"> OFFLINE </span></a></li><li><span class="title-icon "></span><a href="#&#x89E3;&#x8BFB;block&#x7684;insert&#x548C;remove&#x65B9;&#x6CD5;"><b>1.1.2. </b>&#x89E3;&#x8BFB;Block&#x7684;insert&#x548C;remove&#x65B9;&#x6CD5;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5C0F;&#x7ED3;"><b>1.2. </b>&#x5C0F;&#x7ED3;</a></li></ul></ul></div><h1 id="&#x6761;&#x4EF6;v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x548C;&#x66F4;&#x65B0;&#x6E32;&#x67D3;"><a name="&#x6761;&#x4EF6;v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x548C;&#x66F4;&#x65B0;&#x6E32;&#x67D3;" class="anchor-navigation-ex-anchor" href="#&#x6761;&#x4EF6;v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x548C;&#x66F4;&#x65B0;&#x6E32;&#x67D3;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x6761;&#x4EF6;v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x548C;&#x66F4;&#x65B0;&#x6E32;&#x67D3;</h1>
<h2 id="v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;"><a name="v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;" class="anchor-navigation-ex-anchor" href="#v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. v-if&#x7684;&#x9996;&#x6B21;&#x6E32;&#x67D3;</h2>
<p>&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x5728;&#x9759;&#x6001;&#x89C6;&#x56FE;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x52A0;&#x5165;<code>v-if</code>&#x6307;&#x4EE4;&#xFF0C;&#x5E76;&#x901A;&#x8FC7;&#x4EBA;&#x8089;&#x5355;&#x6B65;&#x8C03;&#x8BD5;&#x7684;&#x65B9;&#x5F0F;&#x770B;&#x770B;<code>v-if</code>&#x5230;&#x5E95;&#x662F;&#x5982;&#x4F55;&#x6E32;&#x67D3;&#x7684;&#x5427;&#xFF01;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">v-scope</span>=<span class="hljs-string">&quot;App&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;module&quot;</span>&gt;</span><span class="handlebars"><span class="xml">
  import { createApp } from &apos;https://unpkg.com/petite-vue?module&apos;

  createApp({
    App: {
      $template: `
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;status === &apos;offline&apos;&quot;</span>&gt;</span> OFFLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else-if</span>=<span class="hljs-string">&quot;status === &apos;UNKNOWN&apos;&quot;</span>&gt;</span> UNKNOWN <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else</span>&gt;</span> ONLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
      `,
    }
    status: &apos;online&apos;
  }).mount(&apos;[v-scope]&apos;)
</span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>&#x4EBA;&#x8089;&#x5355;&#x6B65;&#x8C03;&#x8BD5;&#x5F00;&#x59CB;&#xFF1A;</p>
<ol>
<li>&#x8C03;&#x7528;<code>createApp</code>&#x6839;&#x636E;&#x5165;&#x53C2;&#x751F;&#x6210;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;<code>rootScope</code>&#xFF0C;&#x521B;&#x5EFA;&#x6839;&#x4E0A;&#x4E0B;&#x6587;<code>rootCtx</code>&#xFF1B;</li>
<li>&#x8C03;&#x7528;<code>mount</code>&#x4E3A;<code>&lt;div v-scope=&quot;App&quot;&gt;&lt;/div&gt;</code>&#x6784;&#x5EFA;&#x6839;&#x5757;&#x5BF9;&#x8C61;<code>rootBlock</code>&#xFF0C;&#x5E76;&#x5C06;&#x5176;&#x4F5C;&#x4E3A;&#x6A21;&#x677F;&#x6267;&#x884C;&#x89E3;&#x6790;&#x5904;&#x7406;&#xFF1B;</li>
<li>&#x89E3;&#x6790;&#x65F6;&#x8BC6;&#x522B;&#x5230;<code>v-scope</code>&#x5C5E;&#x6027;&#xFF0C;&#x4EE5;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;<code>rootScope</code>&#x4E3A;&#x57FA;&#x7840;&#x8FD0;&#x7B97;&#x5F97;&#x5230;&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;<code>scope</code>&#xFF0C;&#x5E76;&#x4EE5;&#x6839;&#x4E0A;&#x4E0B;&#x6587;<code>rootCtx</code>&#x4E3A;&#x84DD;&#x672C;&#x4E00;&#x540C;&#x6784;&#x5EFA;&#x65B0;&#x7684;&#x4E0A;&#x4E0B;&#x6587;<code>ctx</code>&#xFF0C;&#x7528;&#x4E8E;&#x5B50;&#x8282;&#x70B9;&#x7684;&#x89E3;&#x6790;&#x548C;&#x6E32;&#x67D3;&#xFF1B;</li>
<li>&#x83B7;&#x53D6;<code>$template</code>&#x5C5E;&#x6027;&#x503C;&#x5E76;&#x751F;&#x6210;HTML&#x5143;&#x7D20;&#xFF1B;</li>
<li>&#x6DF1;&#x5EA6;&#x4F18;&#x5148;&#x904D;&#x5386;&#x89E3;&#x6790;&#x5B50;&#x8282;&#x70B9;(&#x8C03;&#x7528;<code>walkChildren</code>)&#xFF1B;</li>
<li>&#x89E3;&#x6790;<code>&lt;span v-if=&quot;status === &apos;offline&apos;&quot;&gt; OFFLINE &lt;/span&gt;</code></li>
</ol>
<h3 id="&#x89E3;&#x6790;span-v-ifstatus--offline-offline-span"><a name="&#x89E3;&#x6790;span-v-ifstatus--offline-offline-span" class="anchor-navigation-ex-anchor" href="#&#x89E3;&#x6790;span-v-ifstatus--offline-offline-span"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.1. &#x89E3;&#x6790;&lt;span v-if=&quot;status === &apos;offline&apos;&quot;&gt; OFFLINE &lt;/span&gt;</h3>
<p>&#x7EC8;&#x4E8E;&#x8981;&#x548C;<code>v-if</code>&#x78B0;&#x5934;&#x4E86;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x7EE7;&#x7EED;&#x4EBA;&#x8089;&#x5355;&#x6B65;&#x8C03;&#x8BD5;&#xFF1A;</p>
<ol>
<li>&#x8BC6;&#x522B;&#x5143;&#x7D20;&#x5E26;&#x4E0A;<code>v-if</code>&#x5C5E;&#x6027;&#xFF0C;&#x8C03;&#x7528;<code>_if</code>&#x539F;&#x6307;&#x4EE4;&#x5BF9;&#x5143;&#x7D20;&#x53CA;&#x5144;&#x5F1F;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x89E3;&#x6790;&#xFF1B;</li>
<li><code>_if</code>&#x5143;&#x6307;&#x4EE4;&#x4F1A;&#x5C06;&#x9644;&#x5E26;<code>v-if</code>&#x548C;&#x8DDF;&#x7D27;&#x5176;&#x540E;&#x7684;&#x9644;&#x5E26;<code>v-else-if</code>&#x548C;<code>v-else</code>&#x7684;&#x5143;&#x7D20;&#x8F6C;&#x5316;&#x4E3A;&#x903B;&#x8F91;&#x5206;&#x652F;&#x8BB0;&#x5F55;(<code>Branch</code>)&#xFF1B;</li>
<li>&#x5FAA;&#x73AF;&#x904D;&#x5386;&#x5206;&#x652F;&#xFF0C;&#x5E76;&#x4E3A;&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#x4E3A;<code>true</code>&#x7684;&#x5206;&#x652F;&#x521B;&#x5EFA;&#x5757;&#x5BF9;&#x8C61;&#x5E76;&#x9500;&#x6BC1;&#x539F;&#x6709;&#x5206;&#x652F;&#x7684;&#x5757;&#x5BF9;&#x8C61;(&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x6CA1;&#x6709;&#x539F;&#x5206;&#x652F;&#x7684;&#x5757;&#x5BF9;&#x8C61;)&#xFF0C;&#x5E76;&#x63D0;&#x4EA4;&#x6E32;&#x67D3;&#x4EFB;&#x52A1;&#x5230;&#x5F02;&#x6B65;&#x961F;&#x5217;&#x3002;</li>
</ol>
<pre><code class="lang-ts"><span class="hljs-comment">// &#x6587;&#x4EF6; ./src/walk.ts</span>

<span class="hljs-comment">// &#x4E3A;&#x4FBF;&#x4E8E;&#x7406;&#x89E3;&#xFF0C;&#x6211;&#x5BF9;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4E86;&#x7CBE;&#x7B80;</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> walk = (node: Node, ctx: Context): ChildNode | <span class="hljs-literal">null</span> | <span class="hljs-built_in">void</span> {
  <span class="hljs-keyword">const</span> <span class="hljs-keyword">type</span> = node.nodeType
  <span class="hljs-keyword">if</span> (<span class="hljs-keyword">type</span> == <span class="hljs-number">1</span>) {
    <span class="hljs-comment">// node&#x4E3A;Element&#x7C7B;&#x578B;</span>
    <span class="hljs-keyword">const</span> el = node as Element

    <span class="hljs-keyword">let</span> exp: <span class="hljs-built_in">string</span> | <span class="hljs-literal">null</span>

    <span class="hljs-keyword">if</span> ((exp = checkAttr(el, <span class="hljs-string">&apos;v-if&apos;</span>))) {
      <span class="hljs-keyword">return</span> _if(el, exp, ctx) <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x6700;&#x8FD1;&#x4E00;&#x4E2A;&#x6CA1;&#x6709;`v-else-if`&#x6216;`v-else`&#x7684;&#x5144;&#x5F1F;&#x8282;&#x70B9;</span>
    }
  }
}
</code></pre>
<pre><code class="lang-ts"><span class="hljs-comment">// &#x6587;&#x4EF6; ./src/directives/if.ts</span>

<span class="hljs-keyword">interface</span> Branch {
  exp?: <span class="hljs-built_in">string</span> | <span class="hljs-literal">null</span> <span class="hljs-comment">// &#x8BE5;&#x5206;&#x652F;&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x8868;&#x8FBE;&#x5F0F;</span>
  el: Element <span class="hljs-comment">// &#x8BE5;&#x5206;&#x652F;&#x5BF9;&#x5E94;&#x7684;&#x6A21;&#x677F;&#x5143;&#x7D20;&#xFF0C;&#x6BCF;&#x6B21;&#x6E32;&#x67D3;&#x65F6;&#x4F1A;&#x4EE5;&#x8BE5;&#x5143;&#x7D20;&#x4E3A;&#x6A21;&#x677F;&#x901A;&#x8FC7;cloneNode&#x590D;&#x5236;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x63D2;&#x5165;&#x5230;DOM&#x6811;&#x4E2D;</span>
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> _if = (el: Element, exp: <span class="hljs-built_in">string</span>, ctx: Context) =&gt; {
  <span class="hljs-keyword">const</span> parent = el.parentElement!
  <span class="hljs-comment">/* &#x951A;&#x70B9;&#x5143;&#x7D20;&#xFF0C;&#x7531;&#x4E8E;v-if&#x3001;v-else-if&#x548C;v-else&#x6807;&#x8BC6;&#x7684;&#x5143;&#x7D20;&#x53EF;&#x80FD;&#x5728;&#x67D0;&#x4E2A;&#x72B6;&#x6001;&#x4E0B;&#x90FD;&#x4E0D;&#x4F4D;&#x4E8E;DOM&#x6811;&#x4E0A;&#xFF0C;
   * &#x56E0;&#x6B64;&#x901A;&#x8FC7;&#x951A;&#x70B9;&#x5143;&#x7D20;&#x6807;&#x8BB0;&#x63D2;&#x5165;&#x70B9;&#x7684;&#x4F4D;&#x7F6E;&#x4FE1;&#x606F;&#xFF0C;&#x5F53;&#x72B6;&#x6001;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x5219;&#x53EF;&#x4EE5;&#x5C06;&#x76EE;&#x6807;&#x5143;&#x7D20;&#x63D2;&#x5165;&#x6B63;&#x786E;&#x7684;&#x4F4D;&#x7F6E;&#x3002;
   */</span>
  <span class="hljs-keyword">const</span> anchor = <span class="hljs-keyword">new</span> Comment(<span class="hljs-string">&apos;v-if&apos;</span>)
  parent.insertBefore(anchor, el)

  <span class="hljs-comment">// &#x903B;&#x8F91;&#x5206;&#x652F;&#xFF0C;&#x5E76;&#x5C06;v-if&#x6807;&#x8BC6;&#x7684;&#x5143;&#x7D20;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E00;&#x4E2A;&#x5206;&#x652F;</span>
  <span class="hljs-keyword">const</span> branches: Branch[] = [
    {
      exp, 
      el
    }
  ]

  <span class="hljs-comment">/* &#x5B9A;&#x4F4D;v-else-if&#x548C;v-else&#x5143;&#x7D20;&#xFF0C;&#x5E76;&#x63A8;&#x5165;&#x903B;&#x8F91;&#x5206;&#x652F;&#x4E2D;
   * &#x8FD9;&#x91CC;&#x6CA1;&#x6709;&#x63A7;&#x5236;v-else-if&#x548C;v-else&#x7684;&#x51FA;&#x73B0;&#x987A;&#x5E8F;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5199;&#x6210;
   * &lt;span v-if=&quot;status=0&quot;&gt;&lt;/span&gt;&lt;span v-else&gt;&lt;/span&gt;&lt;span v-else-if=&quot;status === 1&quot;&gt;&lt;/span&gt;
   * &#x4F46;&#x6548;&#x679C;&#x4E3A;&#x53D8;&#x6210;&lt;span v-if=&quot;status=0&quot;&gt;&lt;/span&gt;&lt;span v-else&gt;&lt;/span&gt;&#xFF0C;&#x6700;&#x540E;&#x7684;&#x5206;&#x652F;&#x6C38;&#x8FDC;&#x6CA1;&#x6709;&#x673A;&#x4F1A;&#x5339;&#x914D;&#x3002;
   */</span>
  <span class="hljs-keyword">let</span> elseEl: Element | <span class="hljs-literal">null</span>
  <span class="hljs-keyword">let</span> elseExp: <span class="hljs-built_in">string</span> | <span class="hljs-literal">null</span>
  <span class="hljs-keyword">while</span> ((elseEl = el.nextElementSibling)) {
    elseExp = <span class="hljs-literal">null</span>
    <span class="hljs-keyword">if</span> (
      checkAttr(elseEl, <span class="hljs-string">&apos;v-else&apos;</span>) === <span class="hljs-string">&apos;&apos;</span> ||
      (elseExp = checkAttr(elseEl, <span class="hljs-string">&apos;v-else-if&apos;</span>))
    ) {
      <span class="hljs-comment">// &#x4ECE;&#x5728;&#x7EBF;&#x6A21;&#x677F;&#x79FB;&#x9664;&#x5206;&#x652F;&#x8282;&#x70B9;</span>
      parent.removeChild(elseEl)
      branches.push({ exp: elseExp, el: elseEl })
    }
    <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">break</span>
    }
  }

  <span class="hljs-comment">// &#x4FDD;&#x5B58;&#x6700;&#x8FD1;&#x4E00;&#x4E2A;&#x4E0D;&#x5E26;`v-else`&#x548C;`v-else-if`&#x8282;&#x70B9;&#x4F5C;&#x4E3A;&#x4E0B;&#x4E00;&#x8F6E;&#x904D;&#x5386;&#x89E3;&#x6790;&#x7684;&#x6A21;&#x677F;&#x8282;&#x70B9;</span>
  <span class="hljs-keyword">const</span> nextNode = el.nextSibling
  <span class="hljs-comment">// &#x4ECE;&#x5728;&#x7EBF;&#x6A21;&#x677F;&#x79FB;&#x9664;&#x5E26;`v-if`&#x8282;&#x70B9;</span>
  parent.removeChild(el)

  <span class="hljs-keyword">let</span> block: Block | <span class="hljs-literal">undefined</span> <span class="hljs-comment">// &#x5F53;&#x524D;&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7ED3;&#x6784;&#x4E3A;true&#x7684;&#x5206;&#x652F;&#x5BF9;&#x5E94;&#x5757;&#x5BF9;&#x8C61;</span>
  <span class="hljs-keyword">let</span> activeBranchIndex: <span class="hljs-built_in">number</span> = <span class="hljs-number">-1</span> <span class="hljs-comment">// &#x5F53;&#x524D;&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7ED3;&#x6784;&#x4E3A;true&#x7684;&#x5206;&#x652F;&#x7D22;&#x5F15;</span>

  <span class="hljs-comment">// &#x82E5;&#x72B6;&#x6001;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x5BFC;&#x81F4;&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7ED3;&#x6784;&#x4E3A;true&#x7684;&#x5206;&#x652F;&#x7D22;&#x5F15;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x9500;&#x6BC1;&#x539F;&#x6709;&#x5206;&#x652F;&#x5BF9;&#x5E94;&#x5757;&#x5BF9;&#x8C61;&#xFF08;&#x5305;&#x542B;&#x4E2D;&#x6B62;&#x65D7;&#x4E0B;&#x7684;&#x526F;&#x4F5C;&#x7528;&#x51FD;&#x6570;&#x76D1;&#x63A7;&#x72B6;&#x6001;&#x53D8;&#x5316;&#xFF0C;&#x6267;&#x884C;&#x6307;&#x4EE4;&#x7684;&#x6E05;&#x7406;&#x51FD;&#x6570;&#x548C;&#x9012;&#x5F52;&#x89E6;&#x53D1;&#x5B50;&#x5757;&#x5BF9;&#x8C61;&#x7684;&#x6E05;&#x7406;&#x64CD;&#x4F5C;&#xFF09;</span>
  <span class="hljs-keyword">const</span> removeActiveBlock = () =&gt; {
    <span class="hljs-keyword">if</span> (block) {
      <span class="hljs-comment">// &#x91CD;&#x65B0;&#x63D2;&#x5165;&#x951A;&#x70B9;&#x5143;&#x7D20;&#x6765;&#x5B9A;&#x4F4D;&#x63D2;&#x5165;&#x70B9;</span>
      parent.insertBefore(anchor, block.el)
      block.remove()
      <span class="hljs-comment">// &#x89E3;&#x9664;&#x5BF9;&#x5DF2;&#x9500;&#x6BC1;&#x7684;&#x5757;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x8BA9;GC&#x56DE;&#x6536;&#x5BF9;&#x5E94;&#x7684;JavaScript&#x5BF9;&#x8C61;&#x548C;detached&#x5143;&#x7D20;</span>
      block = <span class="hljs-literal">undefined</span>
    }
  }

  <span class="hljs-comment">// &#x5411;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;&#x5BF9;&#x7ACB;&#x538B;&#x5165;&#x6E32;&#x67D3;&#x4EFB;&#x52A1;&#xFF0C;&#x5728;&#x672C;&#x8F6E;Event Loop&#x7684;Micro Queue&#x6267;&#x884C;&#x9636;&#x6BB5;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;</span>
  ctx.effect(() =&gt; {
    <span class="hljs-comment">// &#x6B64;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x4EE3;&#x7801;&#x662F;&#x5F02;&#x6B65;&#x6267;&#x884C;&#x7684;</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; branches.length; i++) {
      <span class="hljs-keyword">const</span> { exp, el } = branches[i]
      <span class="hljs-keyword">if</span> (!exp || evaluate(ctx.scope, exp)) {
        <span class="hljs-comment">// &#x82E5;&#x5F53;&#x524D;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#x4E3A;true&#x7684;&#x5206;&#x652F;&#xFF0C;&#x4E0D;&#x662F;&#x6D3B;&#x8DC3;&#x5206;&#x652F;&#xFF0C;&#x90A3;&#x4E48;&#x9700;&#x8981;&#x79FB;&#x9664;&#x6D3B;&#x8DC3;&#x5206;&#x652F;&#xFF0C;&#x5E76;&#x521B;&#x5EFA;&#x65B0;&#x5206;&#x652F;&#x63D2;&#x5165;&#x5230;&#x951A;&#x70B9;&#x5143;&#x7D20;&#x524D;&#x9762;</span>
        <span class="hljs-keyword">if</span> (i !== activeBranchIndex) {
          removeActiveBlock()
          block = <span class="hljs-keyword">new</span> Block(el, ctx)
          block.insert(parent, anchor)
          parent.removeChild(anchor)
          activeBranchIndex = i
        }
        <span class="hljs-keyword">return</span>
      }
    }

    <span class="hljs-comment">// &#x6240;&#x6709;&#x5206;&#x652F;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#x90FD;&#x662F;false&#xFF0C;&#x5219;&#x9700;&#x8981;&#x79FB;&#x9664;&#x6D3B;&#x8DC3;&#x5206;&#x652F;</span>
    activeBranchIndex = <span class="hljs-number">-1</span>
    removeActiveBlock()
  })

  <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x6700;&#x8FD1;&#x4E00;&#x4E2A;&#x4E0D;&#x9644;&#x5E26;`v-if`&#x3001;`v-if-else`&#x6216;`v-else`&#x7684;&#x5144;&#x5F1F;&#x8282;&#x70B9;</span>
  <span class="hljs-keyword">return</span> nextNode
}
</code></pre>
<p>&#x90A3;&#x4E48;&#x5728;&#x7535;&#x8111;&#x8DB3;&#x591F;&#x6162;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x9875;&#x9762;&#x663E;&#x793A;&#x6548;&#x679C;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>&#x7A7A;&#x767D;&#x4E00;&#x7247;</li>
<li><p>&#x663E;&#x793A;&#x6240;&#x6709;&#x5143;&#x7D20;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;status === &apos;offline&apos;&quot;</span>&gt;</span> OFFLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else-if</span>=<span class="hljs-string">&quot;status === &apos;UNKNOWN&apos;&quot;</span>&gt;</span> UNKNOWN <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else</span>&gt;</span> ONLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
</li>
<li><p>&#x6DFB;&#x52A0;&#x951A;&#x70B9;&#x5143;&#x7D20;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- v-if --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;status === &apos;offline&apos;&quot;</span>&gt;</span> OFFLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else-if</span>=<span class="hljs-string">&quot;status === &apos;UNKNOWN&apos;&quot;</span>&gt;</span> UNKNOWN <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else</span>&gt;</span> ONLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
</li>
<li><p>&#x79FB;&#x9664;<code>v-else-if</code></p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- v-if --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;status === &apos;offline&apos;&quot;</span>&gt;</span> OFFLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else</span>&gt;</span> ONLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
</li>
<li><p>&#x79FB;&#x9664;<code>v-else</code></p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- v-if --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;status === &apos;offline&apos;&quot;</span>&gt;</span> OFFLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
</li>
<li><p>&#x79FB;&#x9664;<code>v-if</code>&#xFF0C;&#x53EA;&#x5269;&#x4E0B;&#x951A;&#x70B9;&#x5143;&#x7D20;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- v-if --&gt;</span>
</code></pre>
</li>
<li><p>&#x663E;&#x793A;<code>v-else</code></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-else</span>&gt;</span> ONLINE <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-comment">&lt;!-- v-if --&gt;</span>
</code></pre>
</li>
</ol>
<h3 id="&#x89E3;&#x8BFB;block&#x7684;insert&#x548C;remove&#x65B9;&#x6CD5;"><a name="&#x89E3;&#x8BFB;block&#x7684;insert&#x548C;remove&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x89E3;&#x8BFB;block&#x7684;insert&#x548C;remove&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.2. &#x89E3;&#x8BFB;Block&#x7684;insert&#x548C;remove&#x65B9;&#x6CD5;</h3>
<p>&#x5728;<code>_if</code>&#x5143;&#x6307;&#x4EE4;&#x4E2D;&#x6211;&#x4EEC;&#x770B;&#x5230;&#x5757;&#x5BF9;&#x8C61;<code>block</code>&#x7684;&#x8EAB;&#x5F71;&#xFF0C;&#x5176;&#x5B9E;&#x5757;&#x5BF9;&#x8C61;&#x4E0D;&#x5355;&#x5355;&#x662F;&#x7BA1;&#x63A7;DOM&#x64CD;&#x4F5C;&#x7684;&#x5355;&#x5143;&#xFF0C;&#x800C;&#x4E14;&#x5B83;&#x662F;&#x7528;&#x4E8E;&#x8868;&#x793A;&#x6811;&#x7ED3;&#x6784;&#x4E0D;&#x7A33;&#x5B9A;&#x7684;&#x90E8;&#x5206;&#x3002;&#x5982;&#x8282;&#x70B9;&#x7684;&#x589E;&#x52A0;&#x548C;&#x5220;&#x9664;&#xFF0C;&#x5C06;&#x5BFC;&#x81F4;&#x6811;&#x7ED3;&#x6784;&#x7684;&#x4E0D;&#x7A33;&#x5B9A;&#xFF0C;&#x628A;&#x8FD9;&#x4E9B;&#x4E0D;&#x7A33;&#x5B9A;&#x7684;&#x90E8;&#x5206;&#x6253;&#x5305;&#x6210;&#x72EC;&#x7ACB;&#x7684;&#x5757;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x5C01;&#x88C5;&#x5404;&#x81EA;&#x6784;&#x5EFA;&#x548C;&#x5220;&#x9664;&#x65F6;&#x6267;&#x884C;&#x8D44;&#x6E90;&#x56DE;&#x6536;&#x7B49;&#x64CD;&#x4F5C;&#xFF0C;&#x8FD9;&#x6837;&#x4E0D;&#x4EC5;&#x63D0;&#x9AD8;&#x4EE3;&#x7801;&#x7684;&#x53EF;&#x8BFB;&#x6027;&#x4E5F;&#x63D0;&#x9AD8;&#x7A0B;&#x5E8F;&#x7684;&#x8FD0;&#x884C;&#x6548;&#x7387;&#x3002;</p>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x5B50;&#x5757;&#x5BF9;&#x8C61;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x548C;<code>insert</code>&#x3001;<code>remove</code>&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-comment">// &#x6587;&#x4EF6; ./src/block.ts</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Block {
  <span class="hljs-keyword">constructor</span>(template: Element, parentCtx: Context, isRoot = false) {
    <span class="hljs-keyword">if</span> (isRoot) {
      <span class="hljs-comment">// ...</span>
    }
    <span class="hljs-keyword">else</span> {
      <span class="hljs-comment">// &#x4EE5;v-if&#x3001;v-else-if&#x548C;v-else&#x5206;&#x652F;&#x7684;&#x5143;&#x7D20;&#x4F5C;&#x4E3A;&#x6A21;&#x677F;&#x521B;&#x5EFA;&#x5143;&#x7D20;&#x5B9E;&#x4F8B;</span>
      <span class="hljs-keyword">this</span>.template = template.cloneNode(<span class="hljs-literal">true</span>) as Element
    }

    <span class="hljs-keyword">if</span> (isRoot) {
      <span class="hljs-comment">// ...</span>
    }
    <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">this</span>.parentCtx = parentCtx
      parentCtx.blocks.push(<span class="hljs-keyword">this</span>)
      <span class="hljs-keyword">this</span>.ctx = createContext(parentCtx)
    }
  }
  <span class="hljs-comment">// &#x7531;&#x4E8E;&#x5F53;&#x524D;&#x793A;&#x4F8B;&#x6CA1;&#x6709;&#x7528;&#x5230;&lt;template&gt;&#x5143;&#x7D20;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x5BF9;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4E86;&#x5220;&#x51CF;</span>
  insert(parent: Element, anchor: Node | <span class="hljs-literal">null</span> = <span class="hljs-literal">null</span>) {
    parent.insertBefore(<span class="hljs-keyword">this</span>.template, anchor)
  }

  <span class="hljs-comment">// &#x7531;&#x4E8E;&#x5F53;&#x524D;&#x793A;&#x4F8B;&#x6CA1;&#x6709;&#x7528;&#x5230;&lt;template&gt;&#x5143;&#x7D20;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x5BF9;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4E86;&#x5220;&#x51CF;</span>
  remove() {
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.parentCtx) {
      remove(<span class="hljs-keyword">this</span>.parentCtx.blocks, <span class="hljs-keyword">this</span>)
    }
    <span class="hljs-comment">// &#x79FB;&#x9664;&#x5F53;&#x524D;&#x5757;&#x5BF9;&#x8C61;&#x7684;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x5176;&#x5B50;&#x5B59;&#x8282;&#x70B9;&#x90FD;&#x4E00;&#x5E76;&#x88AB;&#x79FB;&#x9664;</span>
    <span class="hljs-keyword">this</span>.template.parentNode!.removeChild(<span class="hljs-keyword">this</span>.template) 
    <span class="hljs-keyword">this</span>.teardown()
  }

  teardown() {
    <span class="hljs-comment">// &#x5148;&#x9012;&#x5F52;&#x8C03;&#x7528;&#x5B50;&#x5757;&#x5BF9;&#x8C61;&#x7684;&#x6E05;&#x7406;&#x65B9;&#x6CD5;</span>
    <span class="hljs-keyword">this</span>.ctx.blocks.forEach(child =&gt; {
      child.teardown()
    })
    <span class="hljs-comment">// &#x5305;&#x542B;&#x4E2D;&#x6B62;&#x526F;&#x4F5C;&#x7528;&#x51FD;&#x6570;&#x76D1;&#x63A7;&#x72B6;&#x6001;&#x53D8;&#x5316;</span>
    <span class="hljs-keyword">this</span>.ctx.effects.forEach(stop)
    <span class="hljs-comment">// &#x6267;&#x884C;&#x6307;&#x4EE4;&#x7684;&#x6E05;&#x7406;&#x51FD;&#x6570;</span>
    <span class="hljs-keyword">this</span>.ctx.cleanups.forEach(fn =&gt; fn())
  }
}
</code></pre>
<p>&#x7531;<code>v-if</code>&#x3001;<code>v-else-if</code>&#x6216;<code>v-else</code>&#x6807;&#x8BC6;&#x7684;&#x6BCF;&#x4E2A;&#x5206;&#x652F;&#x90FD;&#x4F1A;&#x4E3A;&#x5176;&#x521B;&#x5EFA;&#x72EC;&#x7ACB;&#x7684;&#x5757;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x5F53;&#x5206;&#x652F;&#x88AB;&#x9500;&#x6BC1;&#x65F6;&#x540C;&#x6837;&#x4F1A;&#x4EE5;&#x5757;&#x5BF9;&#x8C61;&#x4E3A;&#x5355;&#x5143;&#x6267;&#x884C;&#x9500;&#x6BC1;&#x64CD;&#x4F5C;&#x3002;</p>
<h2 id="&#x5C0F;&#x7ED3;"><a name="&#x5C0F;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x5C0F;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x5C0F;&#x7ED3;</h2>
<p>&#x7531;&#x4E8E;<code>v-if</code>&#x7684;&#x6E32;&#x67D3;&#x5341;&#x5206;&#x7B80;&#x5355;&#x76F4;&#x63A5;&#xFF0C;&#x6240;&#x4EE5;&#x9996;&#x6B21;&#x6E32;&#x67D3;&#x548C;&#x66F4;&#x65B0;&#x6E32;&#x67D3;&#x53EF;&#x4EE5;&#x5171;&#x4EAB;&#x540C;&#x4E00;&#x5957;&#x903B;&#x8F91;&#x5904;&#x7406;&#xFF0C;&#x4F46;&#x5B83;&#x4F1A;&#x5F15;&#x8D77;&#x6811;&#x7ED3;&#x6784;&#x7684;&#x4E0D;&#x7A33;&#x5B9A;&#xFF0C;&#x56E0;&#x6B64;&#x5FC5;&#x987B;&#x901A;&#x8FC7;&#x5757;&#x5BF9;&#x8C61;(<code>Block</code>)&#x5BF9;&#x6BCF;&#x4E2A;&#x5206;&#x652F;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#x3002;</p>
<script type="text/javascript">
  /**
   * Donation
   */
  function showQR(){
    var rewardButton = document.getElementById('rewardButton')
    var qr = document.getElementById('QR')
    if (rewardButton) {
      rewardButton.style.display = 'none'
    }
    if (qr) {
      qr.style.display = 'block'
    }
  }
  setInterval(showQR, 1000)

  /**
   * Baidu analysis
   */
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?8bca1e3aa362a7f85dbe8304cff65225";
    var s = document.getElementsByTagName("script")[0]; 
    s.parentNode.insertBefore(hm, s);
  })();
</script>


<footer class="page-footer"><span class="copyright">Copyright &#xA9; fsjohnhuang 2022 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">File Modify: 
2022-04-26 09:46:28
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="1_start_from_static_view.html" class="navigation navigation-prev " aria-label="Previous page: 从静态视图首次渲染开始">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="3_initial_rendering_and_rerendering_for_v-for.html" class="navigation navigation-next " aria-label="Next page: 循环v-for的首次渲染和重新渲染">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"条件v-if的首次渲染和重新渲染","level":"2.3","depth":1,"next":{"title":"循环v-for的首次渲染和重新渲染","level":"2.4","depth":1,"path":"1_online_rendering/3_initial_rendering_and_rerendering_for_v-for.md","ref":"1_online_rendering/3_initial_rendering_and_rerendering_for_v-for.md","articles":[]},"previous":{"title":"从静态视图首次渲染开始","level":"2.2","depth":1,"path":"1_online_rendering/1_start_from_static_view.md","ref":"1_online_rendering/1_start_from_static_view.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","theme-comscore","search-pro","code","back-to-top-button","tbfed-pagefooter","chapter-fold","expandable-chapters","splitter","anchor-navigation-ex","donate","sharing-plus","baidu"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy fsjohnhuang 2022"},"chapter-fold":{},"splitter":{},"search-pro":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"code":{"copyButtons":true},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赞赏","title":"","wechat":"/petite-vue-source-reading/images/wechat.jpg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":true},"theme-comscore":{},"back-to-top-button":{},"baidu":{"token":"8bca1e3aa362a7f85dbe8304cff65225"},"sharing":{"qq":false,"all":["qq","qzone","weibo","whatsapp","twitter","facebook","line"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"^_^肥仔John","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"","variables":{},"title":"petite-vue源码剖析","gitbook":"*","description":""},"file":{"path":"1_online_rendering/2_initial_rendering_and_rerendering_for_v-if.md","mtime":"2022-04-26T01:46:28.848Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-05-05T01:20:11.998Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-baidu/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

